package com.dnjn.mes.biz.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.dnjn.mes.biz.domain.MesRegisterAddress;
import com.dnjn.mes.biz.enums.AddrCode;
import com.dnjn.mes.biz.enums.AddrType;
import com.dnjn.mes.common.ext.mybatis.MybatisRedisCache;
import org.apache.ibatis.annotations.*;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * modbus地址对应表 Mapper 接口
 * </p>
 *
 * @author Amber
 * @since 2023-07-26
 */

public interface MesRegisterAddressMapper extends BaseMapper<MesRegisterAddress> {

    @Select("select po.* from mes_register_address po left join mes_equipment e on e.equipment_id = po.equipment_id and e.is_default='Y'")
    List<MesRegisterAddress> fetchCurrentAddress();

    @Select("select po.* from mes_register_address po left join mes_equipment e on e.equipment_id = po.equipment_id and e.is_default='Y' where 1=1 and e.is_default='Y' and po.addr_code=#{addrCode}")
    MesRegisterAddress fetchAddressByAddrCode(@Param("addrCode") AddrCode addrCode);


    @Select("select po.* from mes_register_address po left join mes_equipment e on e.equipment_id = po.equipment_id and e.is_default='Y' where 1=1 and e.is_default='Y' and po.addr_type=#{addrType}")
    List<MesRegisterAddress> fetchAddressByAddrType(@Param("addrType") AddrType addrType);


    Boolean updateAddressByCode(MesRegisterAddress mesRegisterAddress);

    @Select("SELECT a.* FROM mes_register_address a where addr_code in ('MAINTAIN','AWAIT','STOP','RUNNING') ORDER BY address_id ASC")
    ArrayList<MesRegisterAddress> getStatusList();
}
